import {useState, useEffect} from 'react';
import PropTypes from 'prop-types';
import {qrCodeGeneration} from "@/axios/apis.ts";

const RegisterCode = props => {
    const {code} = props;
    const [imgUrl, setImgUrl] = useState<string>('')
    useEffect(() => {
        if (!code) return
        qrCodeGeneration({code}).then(res => {
            // console.log(res);
            setImgUrl(window.URL.createObjectURL(res.data))
        })
    }, [code]);
    return (
        <>{imgUrl && <img src={imgUrl} alt="" width={172}/>}</>
    );
};

RegisterCode.propTypes = {
    code: PropTypes.string.required
};

export default RegisterCode;